﻿using System;
using System.Windows.Automation;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a table control. 
    /// </summary>
    public class UITable : UIBaseControl
    {
        /// <summary>
        /// Specifies the total number of rows in a grid.  
        /// If the control does not support the <see cref="GridPattern"/>, returns -1. 
        /// </summary>
        public new int RowCount
        {
            get { return base.RowCount; }
        }

        /// <summary>
        /// Specifies the ordinal number of the column that contains a cell or item. 
        /// If the control does not support the <see cref="GridItemPattern"/>, returns -1. 
        /// </summary>
        public new int ColumnCount
        {
            get { return base.ColumnCount; }
        }

        /// <summary>
        /// Gets a value which indicates the primary direction of traversal for a table type control.
        /// If the control does not support the <see cref="TablePattern"/> , a null reference is returned.
        /// </summary>
        public new RowOrColumnMajor? RowOrColumnMajor
        {
            get { return base.RowOrColumnMajor; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class. 
        /// </summary>
        public UITable()
            : base(ControlType.Table)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UITable(UIBaseControl parent)
            : base(parent, ControlType.Table)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UITable(string locator)
            : base(null, ControlType.Table, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UITable(UIBaseControl parent, string locator)
            : base(parent, ControlType.Table, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UITable(AutomationElement control) : base(control, ControlType.Table)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UITable"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UITable(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.Table)
        {
        }

        /// <summary>
        /// Retrieves an element that represents the specified cell in a table or grid control. 
        /// </summary>
        /// <param name="row">The ordinal number of the row of interest.</param>
        /// <param name="col">The ordinal number of the column of interest.</param>
        /// <returns>The <see cref="AutomationElement"/> that represents the retrieved cell.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        /// <remarks>Grid coordinates are zero-based with the upper left (or upper right cell depending on locale) having coordinates (0,0).</remarks>
        public new AutomationElement GetItem(int row, int col)
        {
            return base.GetItem(row, col); 
        }

        /// <summary>
        /// Gets a collection of elements that represents all the column headers in a table.
        /// </summary>
        /// <returns>A collection of elements representing the column headers.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new AutomationElement[] GetColumnHeaders()
        {
            return base.GetColumnHeaders();
        }

        /// <summary>
        /// Gets a collection of elements that represents all the row headers in a table.
        /// </summary>
        /// <returns>A collection of elements representing the row headers.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new AutomationElement[] GetRowHeaders()
        {
            return base.GetRowHeaders(); 
        }
    }
}
